Imports DotNetNuke.UI.Utilities
Imports System.Collections.Generic

<ControlMethodClass("MyCompany.MyClass")> _
Partial Class CallbackMethods
    Inherits System.Web.UI.Page

    Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
        DotNetNuke.UI.Utilities.ClientAPI.HandleClientAPICallbackEvent(Me)
        ClientAPI.RegisterControlMethods(Me)
        MyBase.OnInit(e)
    End Sub

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub

    <ControlMethod()> _
    Public Function Add(ByVal x As Integer, ByVal y As Integer) As Integer
        Return x + y
    End Function

    <ControlMethod()> _
    Public Function GetCustomers(ByVal PageSize As Integer) As List(Of Customer)
        Dim ret As List(Of Customer) = New List(Of Customer)()
        For i As Integer = 0 To PageSize
            ret.Add(New Customer(i, "Joe " & i.ToString(), "Smith " & i.ToString()))
        Next
        Return ret
    End Function

    <ControlMethod()> _
    Public Function GetRank(ByVal Customer As Customer) As Customer
        Customer.Rank = 10
        Return Customer
    End Function

    <ControlMethod()> _
    Public Function GetRanks(ByVal Customers As List(Of Customer)) As List(Of Customer)
        Dim i As Integer = 1
        For Each Cust As Customer In Customers
            Cust.Rank = i
            i += 1
        Next
        Return Customers
    End Function

End Class

Public Class Customer
    Private m_ID As Integer
    Private m_FirstName As String
    Private m_LastName As String
    Private m_Rank As Integer

    Public Sub New()

    End Sub

    Public Sub New(ByVal ID As Integer, ByVal FirstName As String, ByVal LastName As String)
        m_ID = ID
        m_FirstName = FirstName
        m_LastName = LastName
    End Sub

    Public Property ID() As Integer
        Get
            Return m_ID
        End Get
        Set(ByVal value As Integer)
            m_ID = value
        End Set
    End Property

    Public Property FirstName() As String
        Get
            Return m_FirstName
        End Get
        Set(ByVal value As String)
            m_FirstName = value
        End Set
    End Property

    Public Property LastName() As String
        Get
            Return m_LastName
        End Get
        Set(ByVal value As String)
            m_LastName = value
        End Set
    End Property

    Public Property Rank() As Integer
        Get
            Return m_Rank
        End Get
        Set(ByVal value As Integer)
            m_Rank = value
        End Set
    End Property

End Class
